package com.xhui.vimarket.zkplus.zul.attr.evt.multi;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.metainfo.ComponentInfo;
import org.zkoss.zul.Listitem;

import com.xhui.crm.common.exception.RtManagerException;com.xhui.vimarket.zkplusui.vimarket.zkplus.zul.attrcom.xhui.vimarket.zkplusrt com.xhui.vimarket.zkplus.zul.acom.xhui.vimarket.zkpluspl;
import com.xhui.vimarket.zkplus.zulcom.xhui.vimarket.zkplusaseComposer;
import com.xhui.vimarkcom.xhui.vimarket.zkplusttr.mod.AttrCompUtil;
import com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrMulcom.xhui.vimarket.zkplus**
 * @版权：福富软件 版权所有 (c) 2010.
 * @文件：com.xhui.vimarket.zkplus.zul.attr.evt.AttrCheckboxComposer.java
 * @所含类：
 * @author: wuyx
 * @version: V1.0
 * @see:
 * @创建日期：2010-12-20
 * @功能说明：客服中心
 * @修改记录： =============================================================<br>
 *        日期:2010-12-20 创建
 *        =============================================================<br>
 */
public class DelBtnComposer extends AttrBaseComposer {
    
    /**
     * serialVersionUID.
     */
    private static final long serialVersionUID = 4579587521568091904L;
    
    @Override
    public ComponentInfo doBeforeCompose(final Page page, final Component comp,
        final ComponentInfo info) {
        return info;
    }
    
    @Override
    public void doAfterCompose(final Component comp) throws Exception {
        super.doAfterCompose(comp);
        // 初始化
        this.init(comp);
    }
    
    /**
     * init.
     * @param comp Component
     */
    public void init(final Component comp) {
    }
    
    /**
     * onClick.
     * 
     */
    public void onClick() {
        // 控件根元素
        final Component rootComp = AttrMultiSubComp.getRootCompByAddOrDelBtn(this.self);
        // 找到上级Listitem
        final Listitem item = AttrMultiSubComp.getListitemByAddOrDelBtn(this.self);
        // Idx
        final long multiIdx = AttrCompUtil.getAttrCompIdx(rootComp);
        if (multiIdx < 0) {
            throw new RtManagerException("多实例控件，获取模板数据错误", this.getClass(), "onClick",
                "multiAttrTmplIdxNull");
        }
        // 获取控件
        final AttrExt attrExt = AttrCompUtil.getAttrExtComp(this.self);
        if (attrExt == null) {
            throw new RtManagerException("多实例控件，获取控件根错误", this.getClass(), "onClick",
                "multiAttrRootCompNull");
        }
        // 获取模板定义
        final AttrTmpl mltiAttrTmpl = AttrCompUtil.getEqualAttrTmpl(attrExt.getAttrSpec()
            .getAttrTmpl(), rootComp);
        if (mltiAttrTmpl == null) {
            throw new RtManagerException("多实例控件，获取模板数据为空", this.getClass(), "onClick",
                "multiAttrTmplNull");
        }
        // 调用增加实例方法，传入本行控件根节点
        AttrMultiSubComp.instance().doDelLine(attrExt, mltiAttrTmpl, item);
        AttrMultiSubComp.fireChangeVal(rootComp);
    }
}
